package com.playball.lottery.frm.buyhall;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import android.app.ListActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.playball.lottery.R;
import com.playball.lottery.ApplicationData;
import com.playball.lottery.customview.BallDTO;
import com.playball.lottery.customview.DelButtonAdapterKuai3;
import com.playball.lottery.customview.MyDialog;
import com.playball.lottery.customview.ShowTipDialog;
import com.playball.lottery.frm.yhzx.BetProtocolActivity;
import com.playball.lottery.frm.yhzx.JddRechargeListActivity;
import com.playball.lottery.frm.yhzx.LoginActivity;
import com.playball.lottery.nt.GetRequestParams;
import com.playball.lottery.util.Constants;
import com.playball.lottery.util.ConvertJsonToList;
import com.playball.lottery.util.DefConstants;
import com.playball.lottery.util.DynArrayInt;
import com.playball.lottery.util.GetIDAsyncLoader;
import com.playball.lottery.util.Kuai3Util;
import com.playball.lottery.util.LotConstants;
import com.playball.lottery.util.MyPreference;
import com.playball.lottery.util.PreferencesUtils;
import com.playball.lottery.util.SysApplication;


/**
 * 快三选号列表界面
 * 
 * @author Administrator
 * 
 */
public class Kuai3ListActivity extends ListActivity implements DefConstants {
	private LinearLayout btnAddRandom;
	private LinearLayout btnBack;
	private LinearLayout btnClear;
	// private Button btnPlus;
	// private Button btnMinus;
	private Button btnBuy;
	// private TextView bsText;
	private EditText zhuihao_EditText;
	private EditText buy_11x5xhlb_EditText01;
	// private TextView sumBsText;
	// private TextView countText;
	private TextView moneyText;

	View buy_elvxhlb_linearlayout01;
	View buy_elvxhlb_linearlayout02;

	private int buy_icon;
	private int playTypeId;
	private int bs = 1;
	private int zh = 1; // 追号
	private int allMoney;
	private int lotID;
	// private String vouchersNo;// 折扣编号
	// private double canDeductMoney;// 折扣金额
	private String issueID;
	private String issueName;
	private String randomBall;

	private DynArrayInt money_dintInt;
	/** 和值号码数组 */
	private DynArrayInt ball_hezhi_dintInt;
	/** 三同号通选 号码数组 */
	private DynArrayInt ball_3ttx_dintInt;
	/** 三连号通选 号码数组 */
	private DynArrayInt ball_3ltx_dintInt;
	/** 三同号单选 号码数组 */
	private DynArrayInt ball_6btn_dintInt;
	/** 二同号单选 号码数组 同号 */
	private DynArrayInt ball_2thdx1_dintInt;
	/** 二同号单选 号码数组 不同号 */
	private DynArrayInt ball_2thdx2_dintInt;

	private ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();

	LinearLayout foot_layout;
	TextView tv_bet_protocol;
	CheckBox cb_bet_protocol;

	private String[] dyn;
	private Context context;
	private PreferencesUtils pUtil;
	private Handler handler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			Bundle b = msg.getData();
			issueID = b.getString("issueID");
			issueName = b.getString("issueName");
		}
	};

	private LinearLayout buy_11x5;
	private LinearLayout gpc_hide;
	private CheckBox iszhuihao;

	// 智能追号按钮
	private Button btnIntelligenceChase;
	// 目前只支持单个
	private ArrayList<HashMap<String, Object>> listIntelligenceChase;
	private int prizeIntellChase;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		// 输入框问题
		getWindow().setSoftInputMode(
				WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
						| WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
		setContentView(R.layout.buy_11x5_list);
		SysApplication.getInstance().addActivity(this);
		context = this;
		pUtil = new PreferencesUtils(context, Constants.PREFERENCES_NAME);
		// 初始化
		initView();
		buy_11x5 = (LinearLayout) findViewById(R.id.buy_11x5);
		LayoutInflater inflater = LayoutInflater.from(this);
		foot_layout = (LinearLayout) inflater.inflate(R.layout.bet_protocol_foot, null);
		tv_bet_protocol = (TextView) foot_layout.findViewById(R.id.bet_protocol);
		cb_bet_protocol = (CheckBox) foot_layout.findViewById(R.id.bet_protocol_choice);
//		tv_bet_protocol.setText(Html.fromHtml("<u>我已满18周岁并同意《服务条款》"));
		tv_bet_protocol.setVisibility(View.VISIBLE);//显示服务协议
		cb_bet_protocol.setChecked(true);
		tv_bet_protocol.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				startActivityForResult(new Intent(Kuai3ListActivity.this, BetProtocolActivity.class), 0);
			}
		});
		this.getListView().addFooterView(foot_layout);

		buy_11x5xhlb_EditText01 = (EditText) findViewById(R.id.buy_11x5xhlb_EditText01);
		// 倍数的焦点事件
		buy_11x5xhlb_EditText01.setOnFocusChangeListener(new OnFocusChangeListener() {

			@Override
			public void onFocusChange(View v, boolean hasFocus) {
				if (hasFocus) {
					gpc_hide = (LinearLayout) findViewById(R.id.gpc_hide);
					gpc_hide.setVisibility(View.GONE);
				}

			}
		});
		buy_11x5xhlb_EditText01.addTextChangedListener(textWatcher);

		// 获得传来的数组，并放入ListView
		Intent intent = getIntent();
		playTypeId = intent.getIntExtra("PlayTypeID", 0);
		allMoney = intent.getIntExtra("AllMoney", 0);
		issueID = intent.getStringExtra("IssueID");
		issueName = intent.getStringExtra("IssueName");
		lotID = intent.getIntExtra("LotID", 0);
		// Log.d("van", "=-- "+lotID);
		// Log.i("Kuai3ListActivity", "onCreate 传送playTypeId= " + playTypeId);
		// Log.i("Kuai3ListActivity", "onCreate 传送allMoney= " + allMoney);
		// Log.i("Kuai3ListActivity", "onCreate 传送issueID= " + issueID);
		// Log.i("Kuai3ListActivity", "onCreate 传送issueName= " + issueName);
		// Log.i("Kuai3ListActivity", "onCreate 传送lotID= " + lotID);

		lotID = intent.getIntExtra("LotID", LOT_ID_KUAI3);
		prizeIntellChase = intent.getIntExtra("prizeIntellChase", 0);
		Log.d("van", "Kuai3ListActivity--" + prizeIntellChase);
		if (issueID == null || issueName == null) {
			GetIDAsyncLoader task = new GetIDAsyncLoader(this, handler, lotID);
			String[] parms = new String[2];
			parms[0] = "200";
			JSONObject jsob = new JSONObject();
			try {
				// 设置请求所需参数
				jsob.put("LottID", lotID);
			} catch (JSONException ex) {
				// TODO Auto-generated catch block
				Log.e("error", ex.toString());
			}
			parms[1] = jsob.toString();
			task.execute(parms);
		}
		moneyText.setText(allMoney + "");
		@SuppressWarnings("unchecked")
		List<BallDTO> arrayList = (ArrayList<BallDTO>) intent.getSerializableExtra("list_elvdto");
		for (BallDTO elvdto : arrayList) {
			String elv_ball = elvdto.getElv_ball();
			list = getData(elv_ball);
		}
		// Log.d("Kuai3ListActivity", "list= "+list.toString());
		initSimpleAdapter(list);

		// 继续添加号码
		btnBack.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent();
				intent.putExtra("playTypeId", playTypeId);
				intent.putExtra("ifbacklist", true);
				intent.putExtra("prizeIntellChase", prizeIntellChase);
				// Log.d("van", prizeIntellChaseTmp+"-");
				intent.setClass(context, Kuai3Activity.class);
				startActivity(intent);
				finish();
			}
		});

		// 清空列表按钮
		btnClear.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (ApplicationData.getInstance().getList_11x5dto().size() > 0) {

					MyDialog.Builder dialog = new MyDialog.Builder(Kuai3ListActivity.this);
					dialog.setTitle("清空号码提示");
					dialog.setMessage("清空后您已选择的号码列表将会清空，确认继续?");
					dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							// 获得自定义的应用程序BallDTO,初始化
							list = new ArrayList<HashMap<String, Object>>();
							ApplicationData.getInstance().initList();
							// 金额清零
							allMoney = 0;
							zh = 1;
							setNoMsg();
							buy_elvxhlb_linearlayout01.setVisibility(View.GONE);
							buy_elvxhlb_linearlayout02.setVisibility(View.VISIBLE);
							initText();
							dialog.cancel();
						}
					});
					dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							dialog.cancel();
						}
					}).create().show();
				}
			}
		});

		// 添加随机号码
		btnAddRandom.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				buy_elvxhlb_linearlayout01.setVisibility(View.VISIBLE);
				buy_elvxhlb_linearlayout02.setVisibility(View.GONE);
				randomBall = "";
				if (playTypeId == 6601) {
					// 开始随机号码
					// int ball_random[] = RandomGenData(3, 18,
					// getRandomNum(playTypeId));
					int ball_random[] = RandomGenData(4, 17, getRandomNum(playTypeId));
					// 追加数组到ball_1st_dintInt中,和值3是111
					ball_hezhi_dintInt = new DynArrayInt();
					ball_hezhi_dintInt.addInt(ball_random);
					// 在这个Activity每选中一注球，所有号码全部存储到xxx_dintInt int[]数组中
					randomBall = ball_hezhi_dintInt.getAllIntToStringForSingle(ball_hezhi_dintInt.getAllInt());
					randomBall = randomBall.substring(0, randomBall.length() - 1);
				} else if (playTypeId == 6602) {
					ball_3ttx_dintInt = new DynArrayInt();
					ball_3ttx_dintInt.addInt(1);
					randomBall = ball_3ttx_dintInt.getAllIntToStringForSingle(ball_3ttx_dintInt.getAllInt());
					if (randomBall.equals("1,")) {
						randomBall = "三同号通选,";
					}
					randomBall = randomBall.substring(0, randomBall.length() - 1);
				} else if (playTypeId == 6603) {
					ball_3ltx_dintInt = new DynArrayInt();
					ball_3ltx_dintInt.addInt(1);
					randomBall = ball_3ltx_dintInt.getAllIntToStringForSingle(ball_3ltx_dintInt.getAllInt());
					if (randomBall.equals("1,")) {
						randomBall = "三连号通选,";
					}
					randomBall = randomBall.substring(0, randomBall.length() - 1);
				} else if (playTypeId == 6604) {// 三同号单选
					// 开始随机号码
					int ball_random[] = RandomGenData(1, 6, getRandomNum(playTypeId));
					// 追加数组到ball_6btn_dintInt中
					ball_6btn_dintInt = new DynArrayInt();
					ball_6btn_dintInt.addInt(ball_random);
					randomBall = ball_6btn_dintInt.getAllIntToStringForSingle(ball_6btn_dintInt.getAllInt());
					// 将 1 2 3 4 5 6转换显示成111 222 333 444 555 666
					randomBall = randomBall.replace("1", "111").replace("2", "222").replace("3", "333")
							.replace("4", "444").replace("5", "555").replace("6", "666");
					randomBall = randomBall.substring(0, randomBall.length() - 1);
				} else if (playTypeId == 6606) {// 二同号复选
					// 开始随机号码
					int ball_random[] = RandomGenData(1, 6, getRandomNum(playTypeId));
					// 追加数组到ball_6btn_dintInt中
					ball_6btn_dintInt = new DynArrayInt();
					ball_6btn_dintInt.addInt(ball_random);
					randomBall = ball_6btn_dintInt.getAllIntToStringForSingle(ball_6btn_dintInt.getAllInt());
					// 将 1 2 3 4 5 6转换显示成11* 22* 33* 44* 55* 66*
					randomBall = randomBall.replace("1", "11*").replace("2", "22*").replace("3", "33*")
							.replace("4", "44*").replace("5", "55*").replace("6", "66*");
					randomBall = randomBall.substring(0, randomBall.length() - 1);
				} else if (playTypeId == 6605 || playTypeId == 6608) {
					// 开始随机号码
					int ball_random[] = RandomGenData(1, 6, getRandomNum(playTypeId));
					// 追加数组到ball_6btn_dintInt中
					ball_6btn_dintInt = new DynArrayInt();
					ball_6btn_dintInt.addInt(ball_random);
					randomBall = ball_6btn_dintInt.getAllIntToStringForSingle(ball_6btn_dintInt.getAllInt());
					randomBall = randomBall.substring(0, randomBall.length() - 1);
				} else if (playTypeId == 6607) {
					randomDirectTwo();
				}
				// 实例化一个新的BallDTO放入到全局变量ApplicationBall中的List_elv里
				BallDTO elvdto = new BallDTO();
				elvdto.setElv_ball(randomBall + "-" + 2);
				// 获得自定义的应用程序BallDTO
				// 将我们放到进程中的全局变量拿出来，看是不是我们曾经设置的值
				// Log.i("application_11x5", "InitLabel:application_11x5_sel:" +
				// app_11x5dto.getList_11x5dto().size());
				// 新选的号码，追加在ApplicationBall全局变量list_ssqdto里
				ApplicationData.getInstance().getList_11x5dto().add(elvdto);
				allMoney += 2;
				ApplicationData.getInstance().setAll_11x5money(allMoney);
				ApplicationData.getInstance().setPlay_11x5Id(playTypeId);
				moneyText.setText(allMoney + "");
				// System.out.println("添加随机号码 ballInfact = " + randomBall);
				initSimpleAdapter(getData(randomBall + "-" + 2));
			}
		});

		// 购买按钮
		btnBuy.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (ApplicationData.getInstance().isUserLogin()) {
					if (issueID == null || issueName == null) {
						Toast.makeText(context, R.string.the_network_is_not_to_force, Toast.LENGTH_SHORT).show();
						return;
					}
					if(bs * allMoney > 2000000){
						Toast.makeText(context, "单个方案的总金额必须在2元至2000000元之间", Toast.LENGTH_SHORT).show();
						return;
					}
					if (list.size() < 1) {
						Toast.makeText(Kuai3ListActivity.this, R.string.betting_number_cannot_be_empty,
								Toast.LENGTH_SHORT).show();
					} /*
					 * else if
					 * (buy_11x5xhlb_EditText01.getText().toString().equals("")
					 * ||
					 * buy_11x5xhlb_EditText01.getText().toString().equals("0"))
					 * { Toast.makeText(Kuai3ListActivity.this,
					 * R.string.buy_at_least_one_times, Toast.LENGTH_SHORT)
					 * .show(); buy_11x5xhlb_EditText01.setText("1"); } else if
					 * (zhuihao_EditText.getText().toString().equals("")) {
					 * zhuihao_EditText.setText("1");
					 * Toast.makeText(Kuai3ListActivity.this,
					 * R.string.period_of_time_can_not_be_empty,
					 * Toast.LENGTH_SHORT).show(); }
					 */else {

						if (cb_bet_protocol.isChecked() == false) {
							Toast.makeText(Kuai3ListActivity.this, R.string.need_to_agree_to_just_can_continue_to_buy,
									Toast.LENGTH_SHORT).show();
							return;
						}
						if (zh == 1) {
							startBuyThread();
						} else {
							startZhuiHaoThread();
						}
					}
				} else {
					Intent intent = new Intent();
					intent.setClass(context, LoginActivity.class);
					startActivity(intent);
				}

			}
		});
		// 智能追号
		btnIntelligenceChase.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {

				if (listIntelligenceChase.size() == 1) {
					if (Constants.LIST_LOTNUM != null) {
						Constants.LIST_LOTNUM.clear();
					}
					String mulStr = listIntelligenceChase.get(0).get("buy_11x5_list_money").toString();
					int mul = Integer.parseInt(mulStr) / 2;
					if (mul == 1) {
						Constants.LIST_LOTNUM.addAll(getLotNum());
						Intent intent = new Intent(Kuai3ListActivity.this, IntelligenceChaseActivity.class);
						intent.putExtra("issueID", issueID);
						intent.putExtra("issueName", issueName);
						intent.putExtra("lotID", lotID);
						intent.putExtra("prizeIntellChase", prizeIntellChase);
						Log.d("van", prizeIntellChase + "");
						startActivityForResult(intent, 1001);
					} else {
						Toast.makeText(Kuai3ListActivity.this, "目前只支持单注", Toast.LENGTH_LONG).show();
					}

				} else if (listIntelligenceChase.size() == 0) {
					Toast.makeText(Kuai3ListActivity.this, "请选择一注", Toast.LENGTH_LONG).show();
				} else {
					Toast.makeText(Kuai3ListActivity.this, "目前只支持单注", Toast.LENGTH_LONG).show();
				}

			}
		});

		buy_11x5.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

			@Override
			public void onGlobalLayout() {
				int heightDiff = buy_11x5.getRootView().getHeight() - buy_11x5.getHeight();
				// 判断焦点在哪里
				if (zhuihao_EditText.hasFocus()) {
					if (heightDiff > 100) {
						// 大小超过100时，一般为显示虚拟键盘事件
						gpc_hide = (LinearLayout) findViewById(R.id.gpc_hide);
						if (zh > 1) {
							gpc_hide.setVisibility(View.VISIBLE);
						} else {
							gpc_hide.setVisibility(View.GONE);
						}
					} else {
						gpc_hide = (LinearLayout) findViewById(R.id.gpc_hide);
						gpc_hide.setVisibility(View.GONE);
					}
				}

			}
		});
	}

	public void onResume() {
		super.onResume();
		
	}

	public void onPause() {
		super.onPause();
		
	}

	// 追号的EditText监听
	private TextWatcher zhuihaoWatcher = new TextWatcher() {
		private boolean isChanged = false;

		@Override
		public void afterTextChanged(Editable s) {
			if (isChanged) {
				return;
			}
			if (!zhuihao_EditText.getText().toString().equals("")) {
				zh = Integer.parseInt(s.toString());
				isChanged = true;
				String str2 = s.toString().trim().replaceFirst("^0*", "");// 正则去除
				if (zh < 1) {
					zhuihao_EditText.setText("1");
					zh = 1;
				} else if (zh > 234) {
					Toast.makeText(Kuai3ListActivity.this, "最多追234期", Toast.LENGTH_SHORT).show();
					zhuihao_EditText.setText("234");
					zh = 234;
				} else {
					gpc_hide = (LinearLayout) findViewById(R.id.gpc_hide);
					if (zh == 1) {
						gpc_hide.setVisibility(View.GONE);
					} else {
						gpc_hide.setVisibility(View.VISIBLE);
					}
					zhuihao_EditText.setText(str2);
				}
				zhuihao_EditText.setSelection(zhuihao_EditText.length());
				isChanged = false;
				zhuihao_EditText.invalidate();
				moneyText.setText(allMoney * zh * bs + "");
			} else {
				/*
				 * if (zhuihao_EditText.getText().toString().equals("")) {
				 * Toast.makeText(Kuai3ListActivity.this,
				 * R.string.period_of_time_can_not_be_empty, Toast.LENGTH_SHORT)
				 * .show();
				 * 
				 * }
				 */
				zh = 1;
			}
			moneyText.setText(allMoney * zh * bs + "");
		}

		@Override
		public void beforeTextChanged(CharSequence s, int start, int count, int after) {
		}

		@Override
		public void onTextChanged(CharSequence s, int start, int before, int count) {
		}

	};

	private TextWatcher textWatcher = new TextWatcher() {
		private boolean isChanged = false;

		public void afterTextChanged(Editable s) {
			if (isChanged) {
				return;
			}
			// TODO Auto-generated method stub
			if (!buy_11x5xhlb_EditText01.getText().toString().equals("")) {

				bs = Integer.parseInt(s.toString());
				isChanged = true;
				String str2 = s.toString().trim().replaceFirst("^0*", "");// 正则去除
				if (bs < 1) {
					buy_11x5xhlb_EditText01.setText("1");
					bs = 1;
				} else if (bs > 999) {
					Toast.makeText(Kuai3ListActivity.this,
							R.string.the_maximum_ratio_of_dig_3_nine, Toast.LENGTH_SHORT).show();
					buy_11x5xhlb_EditText01.setText("999");
					bs = 999;
				} else {
					buy_11x5xhlb_EditText01.setText(str2);
				}
				buy_11x5xhlb_EditText01.setSelection(buy_11x5xhlb_EditText01.length());
				isChanged = false;
				buy_11x5xhlb_EditText01.invalidate();
				moneyText.setText(allMoney * zh * bs + "");
			} else {
				/*
				 * if (buy_11x5xhlb_EditText01.getText().toString().equals(""))
				 * { Toast.makeText(Kuai3ListActivity.this,
				 * R.string.buy_at_least_one_times, Toast.LENGTH_SHORT).show();
				 * 
				 * }
				 */
				bs = 1;
			}
			moneyText.setText(allMoney * zh * bs + "");
		}

		@Override
		public void beforeTextChanged(CharSequence s, int start, int count, int after) {
			// TODO Auto-generated method stub
			Log.d("TAG", "beforeTextChanged--------------->");
		}

		@Override
		public void onTextChanged(CharSequence s, int start, int before, int count) {
			Log.d("TAG", "onTextChanged--------------->");
		}

	};

	class AsyncLoader extends AsyncTask<String, Integer, String> {// 继承AsyncTask

		String action;
		ShowTipDialog showdialog = new ShowTipDialog();

		// 1.准备运行
		protected void onPreExecute() {
			showdialog.showDialog(Kuai3ListActivity.this);
		}

		// 2.正在后台运行
		@Override
		protected String doInBackground(String... paramsArr) {
			// 处理后台执行的任务，在后台线程执行
			String strResult = null;

			action = paramsArr[1];
			// 获取请求返回值
			String UserID = ApplicationData.getInstance().getUserID();
			strResult = GetRequestParams.getRequestUserIDResult(paramsArr[0], UserID, action, getApplicationContext());
			// 获取请求返回值
			return strResult;
		}

		// 3.进度更新
		protected void onProgressUpdate(Integer... progress) {
		}

		// 4.完成后台任务
		protected void onPostExecute(String result) {
			if (result != null) {
				if (action.equals("207")) {
					Buy(result);
				} else if(action.equals("2081")){
					//获取追号期次
					getIssue(result);
				}else {//追号
					Buy2(result);
				}
				showdialog.closeDialog();
			} else {
				Toast.makeText(Kuai3ListActivity.this, getString(R.string.problem_01), Toast.LENGTH_LONG).show();
			}
		}

		// 5.完成后操作
		protected void onCancelled() {
		}

	}

	private void startZhuiHaoThread() {
		//获取期号
		AsyncLoader taskIssure = new AsyncLoader();
		dyn = new String[2];
		JSONObject params = new JSONObject();
		try {
			params.put("LottID", lotID);
			params.put("ChaseCount", zh);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		dyn[0] = params.toString();
		dyn[1] = "2081";
		taskIssure.execute(dyn);
	}

	public void getIssue(String result) {
		List<String> list = new ArrayList<String>();
		Log.d("van", result);
		try {
			JSONArray js = new JSONArray(result);
			for(int i =0;i<js.length();i++){
				JSONObject json = new JSONObject(js.getString(i));
				list.add(json.getString("ID"));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		List<Map<String, Object>> list_LotNum = new ArrayList<Map<String, Object>>();
		list_LotNum = getLotNum();

		AsyncLoader task = new AsyncLoader();
		dyn = new String[2];
		JSONObject params = new JSONObject();
		try {
			JSONArray array = new JSONArray();
			JSONArray array1 = new JSONArray();
			for (int i = 0; i < list_LotNum.size(); i++) {
				JSONObject o = new JSONObject(list_LotNum.get(i));
				array1.put(o);
			}
			for (int j = 0; j < zh; j++) {
				JSONObject json = new JSONObject();
				json.put("IssueID", list.get(j));
				json.put("LotteryNumber", array1);
				json.put("Multiple", bs);
				json.put("Money", bs * allMoney);
				array.put(json);
			}
			params.put("StopMoney", iszhuihao.isChecked() ? 1 : 0);
			params.put("SumNum", allMoney / 2);
			params.put("BuyMoney", bs * allMoney * zh);
			params.put("ChaseIsuses", array);
			params.put("LottID", lotID);
		} catch (JSONException ex) {
			Log.e("error", ex.toString());
		}
		dyn[0] = params.toString();

		dyn[1] = "208";
		task.execute(dyn);

		
	}

	private void startBuyThread() {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		list = getLotNum();

		AsyncLoader task = new AsyncLoader();
		dyn = new String[2];
		JSONObject params = new JSONObject();

		try {
			// 设置请求所需参数
			JSONArray array1 = new JSONArray();
			for (int i = 0; i < list.size(); i++) {
				JSONObject o = new JSONObject(list.get(i));
				// System.out.println(o);
				array1.put(o);
			}
			params.put("SchemeType", 1);// 方案类型 1自购，2合买，3保存 1
			params.put("BetType", 1);// 投注类型 1选号投注 2单式上传 3先发后传 1
			params.put("BonusScale", 0);
			params.put("AssureShare", 0);
			params.put("Description", "");
			params.put("OpenUserList", "");
			params.put("SecrecyLevel", 4);
			params.put("BuyShare", bs * allMoney);
			params.put("Multiple", bs);
			params.put("LotteryID", lotID);
			params.put("IssueID", issueID);
			params.put("IssueName", issueName);
			params.put("Number", array1);
			params.put("Money", bs * allMoney);
		} catch (JSONException ex) {
			// TODO Auto-generated catch block
			Log.e("error", ex.toString());
		}
		dyn[0] = params.toString();
		dyn[1] = "207";
		task.execute(dyn);
	}

	public void Buy2(String strResult) {

		try {
			JSONTokener jsonParser = new JSONTokener(strResult);
			JSONObject js = (JSONObject) jsonParser.nextValue();
			if (Integer.parseInt(js.getString("Code")) < 0) {
				buy_icon = R.drawable.buy_failure;
				String balanceNotFull = js.getString("Data");
				// String balance = "当前余额:"+
				// ApplicationData.getInstance().getUserMoney() +"元" +"\n";

				JSONObject params = new JSONObject();
				params.put("Multiple", bs);
				params.put("LotteryID", lotID);
				params.put("IssueName", issueName);
				params.put("Money", bs * allMoney * zh);

				/*if(js.getString("Data").contains(Constants.BALANCE_BUZU)) {
					Intent intent = new Intent();
					intent.setClass(context, JddRechargeListActivity.class);
					intent.putExtra("params", params.toString());
					startActivityForResult(intent, REQ_CODE_NO_MONEY_2_RECHARGE);
				} else {
					new ShowTipDialog().showBuyInfo(Kuai3ListActivity.this, balanceNotFull, "购买失败", buy_icon,
						params.toString());
				}*/
				new ShowTipDialog().showBuyInfoZH(Kuai3ListActivity.this, balanceNotFull, "购买失败", buy_icon,
						params.toString());

			} else {
				buy_icon = R.drawable.buy_success;

				String msg = "";

				msg = "成功连续追号" + zh + "期\n\n我的认购：" + (allMoney * bs * zh) + "元\n账户余额：" + js.getString("Msg").toString()
						+ "元";

				if (!isFinishing()) {
					new ShowTipDialog().showBuyInfoZH(Kuai3ListActivity.this, msg, "追号成功", buy_icon, dyn[0]);
					clearPUtil();
				}
				// 存贮数据
				MyPreference.getInstance(this).storeBLotID(LotConstants.LOT_ID_SSQ);
			}
		} catch (JSONException ex) {
			// 异常处理代码
			Log.e("error", ex.toString());
		}
	}

	public void Buy(String strResult) {
		try {
			JSONTokener jsonParser = new JSONTokener(strResult);
			JSONObject js = (JSONObject) jsonParser.nextValue();
			if (Integer.parseInt(js.getString("Code")) < 0) {
				buy_icon = R.drawable.buy_failure;
				if(js.getString("Data").contains(Constants.BALANCE_BUZU)) {
					Intent intent = new Intent();
					intent.setClass(context, JddRechargeListActivity.class);
					intent.putExtra("params", dyn[0]);
					startActivityForResult(intent, REQ_CODE_NO_MONEY_2_RECHARGE);
				} else {
					new ShowTipDialog().showBuyInfo(Kuai3ListActivity.this, js.getString("Data"), "购买失败", buy_icon, dyn[0]);
				}
			} else {
				buy_icon = R.drawable.buy_success;

				String msg = "";
				if ("-1".equals(issueName)) {

					msg = "发起快三 " + "  购买方案\n\n我的认购：" + (allMoney * bs)/* + "元\n账户余额："
							+ ConvertJsonToList.getMap(js.getString("Data")).get("Balance").toString()/*
																									 * getBalance
																									 * (
																									 * )
																									 */
							+ "元"+"\n方案编号："+js.getString("Data").toString();
				} else {
					msg = "发起快三 " + issueName + "期购买方案\n\n我的认购：" + (allMoney * bs)/* + "元\n账户余额："
							+ ConvertJsonToList.getMap(js.getString("Data")).get("Balance").toString()/*
																									 * getBalance
																									 * (
																									 * )
																									 */
							+ "元"+"\n方案编号："+js.getString("Data").toString();
				}

				new ShowTipDialog().showBuyInfo(Kuai3ListActivity.this, msg, "投注成功", buy_icon, dyn[0]);
				clearPUtil();
				// 存贮数据
				MyPreference.getInstance(this).storeBLotID(LotConstants.LOT_ID_KUAI3);
			}
		} catch (JSONException e) {
			// 异常处理代码
			Log.e("error", e.toString());
		}
	}

	public String getBalance() {
		String money = "";
		String strResult = null;
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			// 设置请求所需参数
			JSONObject params = new JSONObject();
			// 设置请求action
			String action = "107";// 108获取用户基本信息
			// 获取请求返回值
			String UserID = ApplicationData.getInstance().getUserID();
			strResult = GetRequestParams.getRequestUserIDResult(params.toString(), UserID, action,
					getApplicationContext());
			JSONTokener jsonParser = new JSONTokener(strResult);
			JSONObject js = (JSONObject) jsonParser.nextValue();
			map = ConvertJsonToList.getMap(js.getString("Data"));
			// money =
			// Float.parseFloat(map.get("Balance").toString().replaceAll(",",
			// "").trim());
			money = map.get("Balance").toString();
		} catch (Exception ex) {
			// TODO Auto-generated catch block
			Log.e("error", ex.toString());
		}
		return money;
	}

	/**
	 * 拼接投注号码
	 * 
	 * @return
	 */
	public List<Map<String, Object>> getLotNum() {
		String lotNum = "";
		List<BallDTO> arrayList = ApplicationData.getInstance().getList_11x5dto();
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		for (BallDTO elvdto : arrayList) {
			String lotNum2 = "";
			String elv_ball = elvdto.getElv_ball();
			// Log.e("kuai3list", "getLotNum elv_ball= " + elv_ball.toString());
			elv_ball = elv_ball.substring(0, elv_ball.lastIndexOf("-"));
			elv_ball = elv_ball.replaceAll(" ", ",");
			if (elv_ball.endsWith(",")) {
				elv_ball = elv_ball.substring(0, elv_ball.length() - 1);
			}
			// Log.v("kuai3list", "getLotNum elv_ball= " + elv_ball.toString());
			if (playTypeId == 6601) {// 和值3 =111 和值18=666 6604
				if (elv_ball.contains("111") || elv_ball.contains("666")) {
					// //[{"playid":"6604","number":"111"},{"playid":"6601","number":"5,12,15"}]
					if (elv_ball.equals("111")) {
						Map<String, Object> map = null;
						map = new HashMap<String, Object>();
						map.put("playid", 6604);
						map.put("number", "111");
						list.add(map);
					} else if (elv_ball.equals("666")) {
						Map<String, Object> map = null;
						map = new HashMap<String, Object>();
						map.put("playid", 6604);
						map.put("number", "666");
						list.add(map);
					} else {
						if (elv_ball.contains("111")) {
							Map<String, Object> map = null;
							map = new HashMap<String, Object>();
							map.put("playid", 6604);
							map.put("number", "111");
							list.add(map);
						}
						if (elv_ball.contains("666")) {
							Map<String, Object> map = null;
							map = new HashMap<String, Object>();
							map.put("playid", 6604);
							map.put("number", "666");
							list.add(map);
						}

						// 将String elv_ball= "8,9,5,6,3"; 转化为8,9,5,6,
						String[] strballs = elv_ball.split(",");
						List list1 = Arrays.asList(strballs);
						List newlist = new ArrayList();
						for (int i = 0; i < list1.size(); i++) {
							if (!"111".equals(list1.get(i)) && !"666".equals(list1.get(i))) {
								newlist.add(list1.get(i));
							}
						}
						// System.out.println("list1= " + list1.toString());
						// System.out.println("newlist= " + newlist.toString());

						for (int i = 0; i < newlist.size(); i++) {
							lotNum2 += newlist.get(i) + ",";
						}
						if (lotNum2.endsWith(",")) {
							lotNum2 = lotNum2.substring(0, lotNum2.length() - 1);
						}
						// Log.d("kuai3list", "getLotNum lotNum2= "+lotNum2);
						if (!"".equals(lotNum2)) {
							Map<String, Object> map2 = null;
							map2 = new HashMap<String, Object>();
							map2.put("playid", playTypeId);
							map2.put("number", lotNum2);
							list.add(map2);
						}
					}
				} else {
					lotNum = elv_ball;
					Map<String, Object> map = null;
					map = new HashMap<String, Object>();
					map.put("playid", playTypeId);
					map.put("number", lotNum);
					list.add(map);
				}
			} else if (playTypeId == 6607) {// elv_ball= 33,#5 elv_ball=
											// 33,22,#5,6
				String str1 = elv_ball.split("#")[0];// 转为33,22#5,6
				if (str1.endsWith(",")) {
					str1 = str1.substring(0, str1.length() - 1);
				}
				lotNum = str1 + "#" + elv_ball.split("#")[1];
				Map<String, Object> map = null;
				map = new HashMap<String, Object>();
				map.put("playid", playTypeId);
				map.put("number", lotNum);
				list.add(map);
			} else {
				lotNum = elv_ball;
				Map<String, Object> map = null;
				map = new HashMap<String, Object>();
				map.put("playid", playTypeId);
				map.put("number", lotNum);
				list.add(map);
			}
		}
		// Log.d("kuai3list", "getLotNum list= " + list.toString());
		return list;
	}

	// 二同号单选
	public void randomDirectTwo() {
		int first_ball[] = RandomGenData2THDX(1, 6);
		int second_ball[] = RandomGenData2THDX(1, 6);
		// 判断是否有重复数字
		if (first_ball[0] == second_ball[0]) {
			randomDirectTwo();
		} else {
			ball_2thdx1_dintInt = new DynArrayInt();
			ball_2thdx2_dintInt = new DynArrayInt();

			ball_2thdx1_dintInt.removeAll();
			ball_2thdx2_dintInt.removeAll();

			ball_2thdx1_dintInt.addInt(first_ball);
			ball_2thdx2_dintInt.addInt(second_ball);
			String first = ball_2thdx1_dintInt.getIntToStringForSingle(0);
			first = first.replace("1", "11 #").replace("2", "22 #").replace("3", "33 #").replace("4", "44 #")
					.replace("5", "55 #").replace("6", "66 #");
			// BallRandom2THDX(1, 0, Integer.parseInt(first));
			String second = ball_2thdx2_dintInt.getIntToStringForSingle(0);
			// BallRandom2THDX(0, 1, Integer.parseInt(second));
			randomBall = first + second;// first + "|" + second; 3 33 #
		}
	}

	/**
	 * 二同号单选 机选随机取数
	 * 
	 * @param min
	 *            最小值
	 * @param max
	 *            最大值
	 * @return 一个随机数
	 */
	public int[] RandomGenData2THDX(int min, int max) {
		int[] temp;
		Random rndNumber;
		rndNumber = new Random();
		temp = new int[1];
		List<Integer> a1 = new ArrayList<Integer>();

		for (int i = min; i <= max; i++) {
			a1.add((Integer) i);
		}

		int index = rndNumber.nextInt(max - min + 1);
		Object o = a1.get(index);
		temp[0] = ((Integer) o).intValue();

		a1.remove(index);

		Arrays.sort(temp);
		// Log.d("kuai3list", "RandomGenData2THDX temp[0]= " + temp[0]);
		return temp;
	}

	// 随机取球，并显示
	public int[] RandomGenData(int min, int max, int num) {
		int[] temp;
		Random rndNumber;
		rndNumber = new Random();
		temp = new int[num];
		List<Integer> a1 = new ArrayList<Integer>();

		for (int i = min; i <= max; i++) {
			a1.add((Integer) i);
		}
		for (int i = 0; i < num; i++) {
			int index = rndNumber.nextInt(max - min + 1 - i);
			Object obj = a1.get(index);
			temp[i] = ((Integer) obj).intValue();
			a1.remove(index);
		}
		Arrays.sort(temp);
		return temp;
	}

	// 设置无记录
	public void setNoMsg() {
		List<Map<String, Object>> dataNull = new ArrayList<Map<String, Object>>();
		Map<String, Object> valueMap = new HashMap<String, Object>();
		valueMap.put("Message", "无记录");
		dataNull.add(valueMap);
		SimpleAdapter noMsgAdapter = new SimpleAdapter(Kuai3ListActivity.this, dataNull, R.layout.buy_new11x5_listnum,
				new String[] { "Message" }, new int[] { R.id.buy_11x5_list_ball });
		setListAdapter(noMsgAdapter);
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public void initSimpleAdapter(ArrayList list) {
		listIntelligenceChase = list;
		// Log.v("kuai3list", "initSimpleAdapter list= " + list.toString());
		// DelButtonAdapterKuai3 listAdapter = new
		// DelButtonAdapterKuai3(Kuai3ListActivity.this, list,
		// R.layout.buy_11x5_listnum,
		// new String[] { "buy_11x5_list_ball", "buy_11x5_list_money",
		// "buy_11x5_list_delete" }, new int[] { R.id.buy_11x5_list_ball,
		// R.id.buy_11x5_list_money, R.id.buy_11x5_list_delete },playTypeId);

		DelButtonAdapterKuai3 listAdapter = new DelButtonAdapterKuai3(Kuai3ListActivity.this, list,
				R.layout.buy_new11x5_listnum, new String[] { "buy_11x5_list_ball", "buy_11x5_list_money",
						"buy_11x5_list_delete", "buy_11x5_list_playtype" }, new int[] { R.id.buy_11x5_list_ball,
						R.id.buy_new11x5_list_zhumoney, R.id.buy_11x5_list_delete, R.id.buy_new11x5_list_playtype },
				playTypeId);
		if (listAdapter.GetElvList().size() > 0) {
			list = new ArrayList<HashMap<String, Object>>();
			money_dintInt = new DynArrayInt();
			Iterator<BallDTO> it = ApplicationData.getInstance().getList_11x5dto().iterator();
			for (; it.hasNext();) {
				it.next();
				it.remove();
			}
			for (BallDTO elvdto : listAdapter.GetElvList()) {
				HashMap<String, Object> map = new HashMap<String, Object>();
				String[] ballString = elvdto.getElv_ball().toString().split("-");
				map.put("buy_11x5_list_ball", ballString[0].toString().replace(",", " "));
				map.put("buy_11x5_list_money", ballString[1].toString());
				map.put("buy_11x5_list_delete", R.drawable.default_delbtn02);
				list.add(map);

				elvdto = new BallDTO();
				elvdto.setElv_ball(ballString[0].toString().replace(",", " ") + "-" + ballString[1].toString());

				ApplicationData.getInstance().getList_11x5dto().add(elvdto);

				// 通过传来的单注金额，保存在money_dintInt数组里,计算出总金额
				money_dintInt.addInt(Integer.parseInt(ballString[1]));
				FactoryAllResult();
			}
			setListAdapter(listAdapter);
		} else {
			allMoney = 0;
			// playTypeId = 7001;
			bs = 1;
			initText();
			// 获得自定义的应用程序BallDTO,初始化
			ApplicationData.getInstance().initList();
			setNoMsg();
			buy_elvxhlb_linearlayout01.setVisibility(View.GONE);
			buy_elvxhlb_linearlayout02.setVisibility(View.VISIBLE);
		}

	}

	private ArrayList<HashMap<String, Object>> getData(String elv_ball) {
		// Log.v("kuai3list", "getData elv_ball= " + elv_ball);
		if (!elv_ball.equals("")) {
			String[] ballString = elv_ball.split("-");
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("buy_11x5_list_ball", ballString[0].toString().replace(",", " "));
			map.put("buy_11x5_list_money", ballString[1].toString());
			map.put("buy_11x5_list_delete", R.drawable.default_delbtn02);

			// 玩法
			map.put("buy_11x5_list_playtype", Kuai3Util.getNewKuai3PlayType(playTypeId));

			list.add(map);
		}
		return list;
	}

	private int getRandomNum(int typeId) {
		int num = 0;
		switch (typeId) {
		case 6601:
		case 6602:
		case 6603:
		case 6604:
		case 6606:
			num = 1;
			break;
		case 6605:// 三不同号 随机取3个数做随机号码
			num = 3;
			break;
		// case 6607:
		// num = 1;
		// break;
		case 6608:
			num = 2;
			break;
		}
		return num;
	}

	public void initView() {

		buy_elvxhlb_linearlayout01 = findViewById(R.id.buy_elvxhlb_linearlayout01);
		buy_elvxhlb_linearlayout02 = findViewById(R.id.buy_elvxhlb_linearlayout02);
		buy_11x5xhlb_EditText01 = (EditText) findViewById(R.id.buy_11x5xhlb_EditText01);
		moneyText = (TextView) findViewById(R.id.buy_11x5_money);
		zhuihao_EditText = (EditText) findViewById(R.id.buy_ssqxhlb_zhuihao);
		/*
		 * 追号的焦点事件
		 */
		zhuihao_EditText.setOnFocusChangeListener(new OnFocusChangeListener() {

			@Override
			public void onFocusChange(View v, boolean hasFocus) {
				if (hasFocus) {
					if (zh > 1) {
						gpc_hide.setVisibility(View.VISIBLE);
					}
				} else {
					if (gpc_hide.VISIBLE == View.VISIBLE) {
						gpc_hide.setVisibility(View.GONE);
					}
				}

			}
		});
		zhuihao_EditText.addTextChangedListener(zhuihaoWatcher);
		initText();
		initButton();
		titleBar();

		LinearLayout showOrHideLayout = (LinearLayout) findViewById(R.id.ll_show_hide);
		// IssueID 幸运选号 ""
		int isFromLucky = getIntent().getIntExtra("isfromlucky", 0);
		if (isFromLucky == 1) {
			showOrHideLayout.setVisibility(View.GONE);
			findViewById(R.id.rlzhuihao).setVisibility(View.INVISIBLE);
		} else {
			showOrHideLayout.setVisibility(View.VISIBLE);
			// findViewById(R.id.rlzhuihao).setVisibility(View.VISIBLE);
		}
		iszhuihao = (CheckBox) findViewById(R.id.iszhuihao);
	}

	public void initText() {
		// bsText = (TextView) findViewById(R.id.buy_11x5_list_bs);
		// sumBsText = (TextView) findViewById(R.id.buy_11x5_bs);
		// countText = (TextView) findViewById(R.id.buy_11x5_count);
		buy_11x5xhlb_EditText01.setText("1");
		// countText.setText("0");
		moneyText.setText("0");
		zhuihao_EditText.setText("1");
		// sumBsText.setText("1");
	}

	public void initButton() {
		btnAddRandom = (LinearLayout) findViewById(R.id.buy_11x5_list_addrandom);
		btnBack = (LinearLayout) findViewById(R.id.buy_11x5_list_back);
		btnClear = (LinearLayout) findViewById(R.id.buy_11x5_list_clear);
		// btnPlus = (Button) findViewById(R.id.buy_11x5_list_plus);
		// btnMinus = (Button) findViewById(R.id.buy_11x5_list_minus);
		btnBuy = (Button) findViewById(R.id.buy_11x5_buy);

		btnIntelligenceChase = (Button) findViewById(R.id.btn_intelligence_chase);
	}

	// 计算注数和金额
	public void FactoryAllResult() {
		// 计算注数和金额
		int money = 0;
		for (int i = 0; i < money_dintInt.getSize(); i++) {
			money = money + money_dintInt.getInt(i);
		}
		allMoney = money;
		// bs = Integer.parseInt(buy_11x5xhlb_EditText01.getText().toString());
		ApplicationData.getInstance().setAll_11x5money(allMoney);
		// countText.setText(money / 2 + "");
		moneyText.setText(money * bs * zh + "");
	}

	// TitleBar标题栏
	public void titleBar() {
		// Title信息(返回+Title)
		Button back = (Button) findViewById(R.id.top_title_back);
		back.getBackground().setAlpha(255);// 透明度0~255透明度值 ，值越小越透明
		back.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				onKeyDown(KeyEvent.KEYCODE_BACK, null);
			}
		});

		TextView info = (TextView) findViewById(R.id.top_title_info);
		info.setText("快三");// R.string.buy_kuai3list

		Button refres = (Button) findViewById(R.id.top_title_refres);
		refres.getBackground().setAlpha(255);
		refres.setVisibility(View.INVISIBLE);
		// refres.setBackgroundResource(R.drawable.default_menu);
		// refres.setVisibility(View.VISIBLE);
		refres.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

			}
		});
	}

	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			if (ApplicationData.getInstance().getList_11x5dto().size() != 0) {
				MyDialog.Builder dialog = new MyDialog.Builder(context);
				dialog.setTitle("退出提示");
				dialog.setMessage("是否清除本次选号?");
				dialog.setPositiveButton("清除", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						clearPUtil();

						// 获得自定义的应用程序BallDTO,初始化
						ApplicationData.getInstance().initList();
						dialog.cancel();
						finish();
					}
				});
				dialog.setNegativeButton("保存", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						clearPUtil();
						int size = ApplicationData.getInstance().getList_11x5dto().size();
						pUtil.putInt("kuai3_size", size);
						for (int i = 0; i < size; i++) {
							pUtil.putString("kuai3_ball" + i, ApplicationData.getInstance().getList_11x5dto().get(i)
									.getElv_ball());
						}
						pUtil.putInt("kuai3_allMoney", ApplicationData.getInstance().getAll_11x5money());
						pUtil.putInt("kuai3_play", playTypeId);
						pUtil.putInt("kuai3_prize", prizeIntellChase);
						ApplicationData.getInstance().initList();
						dialog.cancel();
						finish();
						Toast.makeText(context, R.string.design_change_saved, Toast.LENGTH_SHORT).show();
					}
				}).create().show();
			} else {
				// 无对话框退出
				clearPUtil();
				ApplicationData.getInstance().initList();
				finish();
			}
		} else {
			return super.onKeyDown(keyCode, event);
		}
		return true;
	}

	// 清除保存的号码记录
	public void clearPUtil() {
		int size = pUtil.getInt("kuai3_size", 0);
		if (size != 0) {
			for (int i = 0; i < size; i++) {
				pUtil.remove("kuai3_ball" + i);
			}
			pUtil.remove("kuai3_size");
			pUtil.remove("kuai3_allMoney");
			pUtil.remove("kuai3_play");
			pUtil.remove("kuai3_prize");
		}
	}

	@Override
	public void finish() {
		// TODO Auto-generated method stub
		super.finish();
		SysApplication.getInstance().removeActivity(this);
	};

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);

		if (requestCode == 1001 && resultCode == RESULT_OK) {
			finish();
		}

		if (Constants.ZNZH_RES_CODE == resultCode) {
			issueName = data.getExtras().getString("issueName");
			Log.d("van", "-----快三---" + "---" + issueName);
		}

		if (resultCode == RESULT_OK) {
			if (requestCode == REQ_CODE_NO_MONEY_2_RECHARGE) {
				setResult(RESULT_OK);
				finish();
			}
		}
	}

}